<template>
  <van-nav-bar title="血糖" left-text="返回" left-arrow @click-left="onClickLeft" />
  <div class="ab">
    <h1>{{ sugar }}</h1>
    <p>血糖(mmol/L)</p>
    <div class="ae">
      <p>还没有您的血糖记录</p>
      <p>通过智能设备上传或手动录入您的血糖数据，看看健康顾问怎么说</p>
    </div>
  </div>
  <div class="af">
    <h4>近7天记录</h4>
    <div ref="main" style="width: 100%; height: 400px"></div>
    <button
      style="
        width: 100%;
        background: greenyellow;
        color: antiquewhite;
        border: none;
        height: 60px;
        text-align: center;
        margin-top: 40px;
      "
    >
      手动录入
    </button>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import * as echarts from 'echarts'
const router = useRouter()
const main = ref<HTMLDivElement>()
const sugar = ref(4)
const newdata = ref([0, 7, 6, 3, 5, 5, 7, 6, 8, 9, 5])
onMounted(() => {
  const myChart = echarts.init(main.value)
  const option = {
    xAxis: {
      type: 'category',
      data: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
    },
    yAxis: {
      type: 'value',
      splitLine: { show: false },
      axisLabel: {
        formatter: ['18:00', '22:00', '02:00', '06:00', '10:00', '14:00']
      },
      axisLine: { show: false },
      axisTick: { show: false },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      }
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross'
      },
      formatter: '{a} <br/>{b}: {c}小时'
    },
    series: [
      {
        data: newdata.value,
        type: 'line',
        smooth: true
      }
    ]
  }
  myChart.setOption(option)
})
const onClickLeft = () => {
  router.go(-1)
}
</script>
<style>
template {
  background: whitesmoke !important;
}
.ab {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 200px;
  padding: 10px;
  text-align: center;
  background: white;
  margin-top: 10px;
  .ae {
    width: 100%;
    height: 90px;
    background: whitesmoke !important;
    margin-top: 20px;
    text-align: left;
    line-height: 40px;
  }
}
.af {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 500px;
  padding: 10px;
  text-align: center;
  background: white;
  margin-top: 10px;
}
</style>
